package com.songtai.service.impl;

import java.util.List;

import com.songtai.dao.NewsDao;
import com.songtai.po.News;
import com.songtai.service.NewsService;
import com.songtai.util.Pager;

/**
 * @author 赵中杨
 * @email zhaozhongyang717@gmail.com
 * @date 2010 2010-4-19 下午05:01:44
 * @category 新闻操作业务逻辑实现类
 */
public class NewsServiceImpl implements NewsService {
	private NewsDao newsDao;

	/**
	 * 增加新闻
	 */
	@Override
	public void addNews(News news) {
		newsDao.addNews(news);
	}

	/**
	 * 获取指定节点下的所有新闻
	 */
	@Override
	public Pager<News> getNewsListByNodeid(Long nodeid, int currentPage, int pageSize) {
		return newsDao.getNewsByNodeid(nodeid, currentPage, pageSize);
	}

	/**
	 * 删除新闻
	 */
	@Override
	public boolean deleteNews(String newsid) {
		return newsDao.deleteNews(newsid);
	}

	/**
	 * 改变新闻状态
	 */
	@Override
	public int changeNewsStatus(String status1, String status2, String newsid) {
		return newsDao.changeNewsStatus(status1, status2, newsid);
	}

	/**
	 * 按ID获取新闻
	 */
	@Override
	public News getNewsById(Long newsid) {
		return newsDao.getNewsById(newsid);
	}

	/**
	 * 更新新闻
	 */
	@Override
	public void updateNews(News news) {
		News newNews = newsDao.getNewsById(news.getId());
		if (newNews != null) {
			newNews.setContent(news.getContent());
			newNews.setStatus(news.getStatus());
			newNews.setTitle(news.getTitle());
			newNews.setSummary(news.getSummary());
			newsDao.updateNews(newNews);
		}
	}

	@Override
	public List<News> getRecentNews(int pageSize,Long nodeid) {
		return newsDao.getRecentNews(pageSize,nodeid);
	}

	/**
	 * 获取所有新闻
	 */
	@Override
	public Pager<News> getNews(int currentPage, int pageSize) {
		return newsDao.getAllNews(currentPage, pageSize);
	}

	/**
	 * 按关键字搜索新闻
	 */
	@Override
	public Pager<News> searchNews(int currentPage, int pageSize, String keyword) {
		return newsDao.searchNews(currentPage, pageSize, keyword);
	}

	/**
	 * @return the newsDao
	 */
	public NewsDao getNewsDao() {
		return newsDao;
	}

	/**
	 * @param newsDao
	 *            the newsDao to set
	 */
	public void setNewsDao(NewsDao newsDao) {
		this.newsDao = newsDao;
	}

}
